#coding:utf-8
'''
create on 2017-07-15

@author: sandy
'''

import logging
import time
import Game
import Center
import CenterBuild
from pycommon import Const
from pycommon import Utils
import ClientFactory

LOCK_MONEY_STATE_NONE       =   1
LOCK_MONEY_STATE_LOCKING    =   2
LOCK_MONEY_STATE_LOCKED     =   3
LOCK_MONEY_STATE_FAILED     =   4

class UserBase(object):
    
    def __init__(self,uid):
        
        self.uid = uid
        self.session = 0
        self.sex = 0
        self.photo = u''
        self.nickname = u''

        self.hallId = -1
        self.tableId = -1
        self.seatnum = -1
        
        self.prop = {}
        self.property = {}
        self.bPause = False


    def setPause(self, bFlag):
        self.bPause = bFlag
        
    def getPause(self):
        return self.bPause
    
    def getUid(self):
        return self.uid

    def getSession(self):
        return self.session
    
    def changeSession(self, s):
        self.session = s   
    
    def getSex(self):
        return self.sex
    
    def getNickname(self):
        return self.nickname
    
    def getPhoto(self):
        return self.photo
    
    def setHallId(self, hallId):
        self.hallId = hallId
        
    def getHallId(self):
        return self.hallId

    def setTableId(self,tableId):
        self.tableId = tableId

    def getTableId(self):
        return self.tableId
    
    def setSeatNum(self, num):
        self.seatnum = num
        
    def getSeatNum(self):
        return self.seatnum
    
    def getLoginTime(self):
        return self.logintime

    def getProp(self):
        return self.prop
    
    def getProperty(self):
        return self.property

    def addProp(self,pid,pvalue):
        self.prop[pid] = pvalue
        logging.debug("addProp pid=%d pvalue=%d",pid,pvalue)

    def addProperty(self,pid,pvalue):
        self.property[pid] = pvalue
        logging.debug("addProperty pid=%d pvalue=%d",pid,pvalue)
           
    def setUserBaseInfo(self,uid,session,sex,photo,nickname):
        self.uid = uid
        self.session = session
        self.sex = sex
        self.photo = photo
        self.nickname = nickname
        logging.debug(u"setInfo() uid=%d nickname=%s",self.uid,nickname)

    def sendPacket(self, pkt):
        if True == self.bPause:
            logging.warn(u"UserBase.sendPacket() self.bPause is True")
            return
        client = ClientFactory.instance.getClientSrvByUid(self.uid)
        if client:
            client.sendPacket(pkt)
        else:
            logging.warn(u"UserBase.sendPacket() self.client is None")
    
    def kick(self):
        client = ClientFactory.instance.getClientSrvByUid(self.uid)
        if client:
            client.kick()
        else:
            logging.warn(u"UserBase.kick() self.client is None")
    
    def onLoginSuc(self):
        self.logintime = time.time()
    
    def onLeave(self):
        Game.instance.onUserLeave(self.uid)   
    
        
        
if __name__ == '__main__':
    pass